<?php

class mysql {

    var $host;
    var $db;
    var $user;
    var $pass;

    public function __construct($host,$db,$user,$pass) {

        $this->host = $host;
        $this->db = $db;
        $this->username = $user;
        $this->pass = $pass;

        $this->mysqli = new mysqli($this->host, $this->username, $this->pass, $this->db);

        if ($this->mysqli->connect_errno) {
            echo "Failed to connect to MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error;
        }

    }

    public function write($query) {

        if (!$this->mysqli->query("$query") === TRUE) {
            printf("Error: %s\n", $this->mysqli->error);
        }

    }

    public function select($query) {

        $result = $this->mysqli->query($query);

        $rows = array();

        while($row = $result->fetch_array()) {
            $rows[] = $row;
        }

        return $rows;

    }

    public function __destruct() {

        $this->mysqli->close();

    }

}

?>
